using System;
using System.ComponentModel;
#if NETFX_CORE
using Windows.UI.Xaml.Markup;
#else
using System.Windows.Markup;
#endif

namespace Prometheus.Binding.Validation
{
    /// <summary>
    /// Can be used to validate by validation rules with out of data context
    /// </summary>
    [ContentProperty(
#if NETFX_CORE
        Name=
#endif
"ValidationRules")]
    public class proNullContextBinding : proValidationBinding
    {
        public proNullContextBinding(string elementPropertyPath) : this(elementPropertyPath, null)
        {
        }

        public proNullContextBinding() : this(string.Empty, string.Empty)
        {
        }

        public proNullContextBinding(string elementPropertyPath, string dataContextPropertyPath)
            : base(elementPropertyPath, dataContextPropertyPath)
        {
            NotifyOnIDataErrorException = false;
            NotifyOnSetterException = false;
            NotifyOnSetterValidationException = false;
        }

        protected override void ToData()
        {
            //doing nothing,' cause there is no any data context
            //but checking errors
            ProcessGroupUpdate();
            ProcessErrors();
        }

        protected override void SetValueToData(object convertedValue)
        {
            //doing nothing
        }

        protected override void CurrentDataContextChanged(object oldDataContext)
        {
            //we dont react to it
        }


        protected override void dataContext_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            //it must not be called
            //checking for this
            throw new InvalidOperationException("Fatal error, please look for source comments");
        }

        protected override void FromData()
        {
            //doing nothing
        }
    }
}